#!/usr/bin/python

import os

fileName = "makefile"

f = open(fileName,"w+")


f.write("CPP = g++\n")
f.write("CXXFLAGS = -o\n")
f.write("LDFLAGS = -lSDL -lcurl -lSDL_image\n")
f.write("EXEC = killmario\n")
f.write("all: $(EXEC)\n\n")



f.write("%.o: %.cpp\n")
f.write("\t$(CPP) $(CXXFLAGS) $@ -c $< $(LDFLAGS)\n\n")


f.write("clean:\n")
f.write("\trm -rf *.o\n\n")

f.write("mrproper: clean\n")
f.write("\trm -rf $(EXEC)\n\n\n")


files = []

for fil in os.listdir("./"):
	if len(fil)>4:
		if fil[-4:]==".cpp":
			s = fil
			s = s[0:-4]
			files.append(s)


f.write("$(EXEC): ");

for fil in files:
	f.write(fil+".o ")

f.write("\n\t$(CPP) ")
for fil in files:
	f.write(fil+".o ")

f.write("-o $(EXEC) $(LDFLAGS)\n")


f.write("\n\n")
f.close()


for fil in files:
	os.system("gcc -MM "+fil+".cpp >> "+fileName)
	#print "gcc -MM "+fil+".cpp >> "+fileName


